module.exports = function ($scope, $state, $resource, $modal, toaster,$stateParams ){


    //查询法律法规类型列表
    $scope.search = function (pageNo){
        var para = {
            'type': $stateParams.type,
            'key' : $scope.info.key,
            'value' : $scope.info.value
            
        }
        $resource('/api/as/goc/pelawinfo/findTypeList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.list = res.data.results;
                $scope.totalItems = res.data.totalRecord;

                $scope.currentPage = pageNo;
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        }); 
    }
  
     //添加or修改
     $scope.saveType = function(info) {
         if(info){
            var para = {
                'type': $stateParams.type,
                'id' : info.id,
                'key' : info.key,
                'value' :info.value
                
            }
         }else{
            var para = {
                'type': $stateParams.type
            }
         }
        
        var modalInstance = $modal.open({
            template: require('../views/saveTypeInfo.html'),
            controller: 'saveTypeInfo',
            size: 'lg',
            resolve: {
                item : function () {
                    return para;
                },
                flag : function () {
                    return para == 1;
                }
            }
        });
        //关闭模态框刷新页面
        modalInstance.result.then(function() {
            init();
        });
    }

    //保存法律法规类型
    // $scope.saveType = function (info){
    
    //     var para = {
    //         'type': '1',
    //         'id' : info.id,
    //         'key' : $scope.info.key,
    //         'value' : $scope.info.value
    //     }
    //     $resource('/api/as/goc/pelawinfo/savetype', {}, {}).save(para, function(res){
    //         if(res.errcode === 0){
    //             toaster.success({title: '', body: '成功'});
    //             $scope.search(1);
    //         }else{
    //             toaster.error({title: '', body: res.errmsg});
    //         }
    //     }); 
    // }
         


    init();
    //初始化列表
    function init(){
        $scope.currentPage = 1;		//当前页码
        $scope.itemsPerPage = 10;	//每页显示几条
        $scope.searchform = {};
        $scope.search(1);
    }

        
    

    //删除
    $scope.delete = function (info){
        var para = {
            'id' : info.id
        }
        $resource('/api/as/goc/pelawinfo/delType', {}, {}).get(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '删除成功'});
                init();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

   
};